#include "qdynamichighlighter.h"

QDynamicHighlighter::QDynamicHighlighter(QTextDocument *parent):
    QSyntaxHighlighter(parent)
{
    RegExpPattern = QString("qqq");
}

QDynamicHighlighter::~QDynamicHighlighter()
{
    //
}

void QDynamicHighlighter::highlightBlock(const QString &text)
{
        QRegExp expression(RegExpPattern);

        QTextCharFormat format;
        format.setForeground(Qt::darkGreen);
        format.setFontWeight(QFont::Bold);

        int index = expression.indexIn(text);
        while (index >= 0) {
            int length = expression.matchedLength();
            setFormat(index, length, format);
            index = expression.indexIn(text, index + length);
        }
}

void QDynamicHighlighter::SetPattern(const QString &pattern)
{
    RegExpPattern.clear();
    RegExpPattern = pattern;
}


